
#include "Vector2.h"
#include <cmath>
#include <algorithm>

using namespace Iride;

Vector2::Vector2(): x(0.0),y(0.0)
{
};

Vector2::Vector2(Real fx, Real fy): x(fx), y(fy)
{
};

void Vector2::Swap(Vector2 &rOther)
{
	std::swap(x, rOther.x);
	std::swap(y, rOther.y);
}

Vector2 Vector2::operator- (void) const
{
	Vector2 result;
	result.x = - x;
	result.y = - y;

	return result;
}

Vector2 Vector2::operator+ (const Vector2& vec) const
{
	Vector2 result;
	result.x = x + vec.x;
	result.y = y + vec.y;

	return result;
}

Vector2 Vector2::operator- (const Vector2& vec) const
{
	Vector2 result;
	result.x = x - vec.x;
	result.y = y - vec.y;

	return result;
}

Vector2 Vector2::operator* (const Real& coeff) const
{
	Vector2 result;
	result.x = coeff*x;
	result.y = coeff*y;

	return result;
}

Vector2 Vector2::operator/ (const Real& coeff) const
{
	Vector2 result;
	result.x = x/coeff;
	result.y = y/coeff;

	return result;
}

Vector2& Vector2::operator+= (const Vector2& vec)
{
  *this = *this + vec;
  return *this;
}

Vector2& Vector2::operator-= (const Vector2& vec)
{
  *this = *this - vec;
  return *this;
}

Real Vector2::Length() const
{
	return sqrt(x*x + y*y);
}

bool Vector2::Normalize()
{
	Real Den = 1.0;

	Den = x*x + y*y;

	Den = sqrt(Den);

	if (Den != 0.0)
	{
		x=x/Den;
		y=y/Den;

		return true;
	}
	else
	{
		return false;
	}
}

Vector2 Vector2::Lerp (Vector2 vecA, Vector2 vecB, Real coeff )
	{
		return vecA * coeff + vecB * (1.0 - coeff);
	}

const Vector2 Vector2::Zero = Vector2(0.0,0.0);
